@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout_List.cshtml";
}

@section toolbar{
    <a id="add" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
    <a id="edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
    <a id="delete" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
    <a id="detail" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">详情</a>
}

@section search{
    <div class="search_wrapper">
        <div class="search_item">
            <label class="search_label">查询类别</label>
            <select name="condition" class="easyui-combobox" data-options="width:100">
                <option value="">请选择</option>

                <option value="GroupName">客户组名称</option>
            </select>
            <input name="keyword" class="easyui-textbox" style="width:150px" />
        </div>
        <div class="search_submit">
            <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchGrid(this,'#dataTable')">查询</a>
        </div>
    </div>
}
<div id="dataTable">

</div>

<script>
    var rootUrl = '@Url.Content("~/")';
    var formWidth = 500;
    var formHeight = 375;

    function initTable() {
        $('#dataTable').datagrid({
            url: rootUrl + 'Crm/Crm_CusGroup/GetDataList',
            method: 'POST',
            //queryParams: { 'id': id },
            idField: 'GroupId',
            fit: true,
            fitColumns: true,
            singleSelect: false,
            selectOnCheck: false,
            checkOnSelect: false,
            sortName: 'GroupId',
            sortOrder: 'Desc',
            rownumbers: true,
            pagination: true,
            pageSize: 30,
            //nowrap: false,
            pageList: [10, 30, 50, 100, 200, 500, 1000],
            //showFooter: true,
            columns: [[
                { title: 'ck', field: 'ck', checkbox: true },

                { title: '客户组名称', field: 'GroupName', width: 200 },
                { title: '状态', field: 'StatusName', width: 200 },
                { title: '创建时间', field: 'CreateTime', width: 200 }
            ]],
            onBeforeLoad: function (param) {

            },
            onBeforeSelect: function () {
                return false;
            }
        });
    }

    $(function () {
        initTable();
        
        //添加数据
        $('#add').click(function () {
            dialogOpen({
                id: 'form',
                title: '添加数据',
                width: formWidth,
                height: formHeight,
                url: rootUrl + 'Crm/Crm_CusGroup/Form',
            });
        });

        //修改数据
        $('#edit').click(function () {
            var selected = $("#dataTable").datagrid("getChecked");
            if (!selected || !selected.length) {
                dialogError('请选择要修改的记录!');
                return;
            }
            var id = selected[0].GroupId;

            dialogOpen({
                id: 'form',
                title: '修改数据',
                width: formWidth,
                height: formHeight,
                url: rootUrl + 'Crm/Crm_CusGroup/Form?id=' + id,
            });
        });

        //删除数据
        $('#delete').click(function () {
            var checked = $("#dataTable").datagrid("getChecked");
            if (!checked || !checked.length) {
                dialogError('请选择要删除的记录!');
                return;
            }
            var ids = $.map(checked, function (item) {
                return item['GroupId'];
            });

            dialogComfirm('确认删除吗？', function () {
                $.postJSON(rootUrl + 'Crm/Crm_CusGroup/DeleteData', { ids: JSON.stringify(ids) }, function (resJson) {
                    if (resJson.Success) {
                        $('#dataTable').datagrid('clearSelections').datagrid('clearChecked');
                        $('#dataTable').datagrid('reload');
                        dialogMsg('删除成功!');
                    }
                    else {
                        dialogError(resJson.Msg);
                    }
                });
            });
        });

        
        //报价组详情
        $('#detail').click(function () {
            var selected = $("#dataTable").datagrid("getChecked");
            if (!selected || !selected.length) {
                dialogError('请选择要查看的记录!');
                return;
            }
            var groupId = selected[0].GroupId;

            dialogOpen({
                id: 'form',
                title: '报价组详情',
                width: $(window).width(),
                height: $(window).height(),
                url: rootUrl + 'Crm/Crm_CusGroDetail/Index?groupId=' + groupId,
            });
        });



    });
</script>